package com.atguigu.gulimall.search.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gulimall.search.entity.Goods;
import com.atguigu.gulimall.search.service.SearchBizService;
import com.atguigu.gulimall.search.vo.SearchParamVo;
import com.atguigu.gulimall.search.vo.SearchResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author nicc
 * @version 1.0
 * @className SearchController
 * @date 2022-10-13 03:45
 */

@RequestMapping("/api/inner/search")
@RestController
public class SearchController {


    @Autowired
    SearchBizService searchService;


    /**
     * 更新热度分
     * @param skuId
     * @param hotScore
     * @return
     */
    @GetMapping("/hotscore/{skuId}")
    public Result updateHotScore(@PathVariable("skuId") Long skuId,
                                 @RequestParam("hotScore") Long hotScore){
        searchService.updateHotScore(skuId,hotScore);
        return Result.ok();
    }


    /**
     * 检索商品
     * @param paramVo
     * @return
     */
    @PostMapping("/sku/search")
    public Result<SearchResponseVo> search(@RequestBody SearchParamVo paramVo){


        SearchResponseVo responseVo = searchService.search(paramVo);

        return Result.ok(responseVo);
    }


    @PostMapping("/onsale")
    public Result onSaleGoods(@RequestBody Goods goods){


        searchService.onSaleGoods(goods);

        return Result.ok();
    }

    @DeleteMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable("skuId") Long skuId){
        searchService.cancelSaleGoods(skuId);
        return Result.ok();
    }
}
